package com.pyb.common.upload.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * FileUploadController
 *
 * @author chuchen.zhang
 * @date 17-2-19 下午9:55
 */
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public class FileUploadController {

	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public String imgUpload(@RequestParam(value = "file", required = false) MultipartFile file) {
		if (!file.isEmpty()) {
			//生成uuid作为文件名称
			String uuid = UUID.randomUUID().toString().replaceAll("-", "");
			//获得文件类型（可以判断如果不是图片，禁止上传）
			String contentType = file.getContentType();
			//获得文件后缀名称
//			String imageName = contentType.substring(contentType.indexOf("/") + 1);
		}
		return null;
	}
}
